package com.you.learning.springcloud.order.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * 初始化MQ的信息，比如程序启动的时候，创建交换机、队列等信息
 */
@Configuration
public class RabbitMQAdminConfig {

    /**
     * 创建一个topicQueue
     *
     * @return
     */
    @Bean
    public Queue springBootTopicQueue1() {
        Map<String, Object> args = null;
        return new Queue("springBootTopicQueue1", true, false, false, args);
    }

    /**
     * 创建一个topicExchange
     *
     * @return
     */
    @Bean
    public TopicExchange springBootTopicExchange1() {
        Map<String, Object> args = null;
        return new TopicExchange("springBootTopicExchange1", true, false, args);
    }

    @Bean
    public Binding bindTopicQueueExchange() {
        String routeKey = "springBootTopicRouteKey.#";
        return BindingBuilder.bind(springBootTopicQueue1()).to(springBootTopicExchange1()).with(routeKey);
    }


}
